﻿using System;
using System.Collections.Generic;
using System.Xml;
using System.Collections.ObjectModel;

namespace Syfuhs.APIWrappers.LiveMeeting
{
    /// <summary>
    /// Live Meeting
    /// </summary>
    public class Meeting : ParsedType
    {
        public Meeting() { }

        public ApplicationSharingOption ApplicationSharingNow { get; set; }
        
        public string AudienceInviteText { get; set; }
        
        public DateTime CreateTime { get; set; }
        
        public bool IsOngoing { get; set; }
        
        public string Mid { get; set; }
        
        public string Owner { get; set; }
        
        public string PresenterInviteText { get; set; }
        
        public bool ServerGeneratedAudiencePassword { get; set; }
        
        public bool ServerGeneratedPresenterPassword { get; set; }

        public Status Status { get; set; }
        
        public DateTime StartTime { get; set; }
        
        public DateTime EndTime { get; set; }
        
        public string Name { get; set; }
        
        public string Title { get; set; }
        
        public string AudiencePassword { get; set; }
        
        public string PresenterPassword { get; set; }
        
        public double MaxUsers { get; set; }

        public override string ToString()
        {
            return Name;
        }
    }

    static class MeetingResponseParser
    {
        public static Meeting[] ParseCollection(XmlDocument response)
        {
            List<Meeting> meetings = new List<Meeting>();

            foreach (XmlNode node in response.SelectNodes("PlaceWareConfCenter/ListMeetingsReply/MeetingReply"))
                meetings.Add((Meeting)TypeParser.ParseXmlNodes(new Meeting(), node.SelectNodes("OptionList")));

            return meetings.ToArray();
        }

        public static Meeting Parse(XmlDocument response)
        {
            return (Meeting)TypeParser.ParseXmlNodes(new Meeting(), response.SelectNodes("PlaceWareConfCenter/ListMeetingsReply/MeetingReply/OptionList"));
        }
    }
}
